# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: 04-mongo入库实战.py
"""

'''
采集腾讯招聘数据 进行入库
https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1653659591464&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=python&pageIndex=2&pageSize=10&language=zh-cn&area=cn
'''



import requests
import pymongo
client = pymongo.MongoClient()
db = client.xxx
collection = db.xialuo

def get_data():
    url = "https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1653659591464&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=python&pageIndex=2&pageSize=10&language=zh-cn&area=cn"
    res = requests.get(url).json()
    items = res.get('Data').get('Posts')
    for item in items:
        save_data(item)

def save_data(data):
    if isinstance(data,dict):
        collection.insert(data)
    else:
        return '数据类型有问题'

get_data()

